package com.dycong.common.leetcode;

/**
 * @author dycong
 * @date 2019/8/5 9:12
 */
public class CountAndSay_38 {

    public static void main(String[] args) {
        System.out.println(countAndSay(12));
    }


    public static String countAndSay(int n) {
        String s = "1";
        int k;
        for (int i = 1; i < n; i++) {
            StringBuilder t = new StringBuilder();
            for (int j = 0; j < s.length(); j = k) {
                k = j;
                //找有几个相同的.
                while (k < s.length() && s.charAt(k) == s.charAt(j)) {
                    k++;
                }
                t.append(k - j).append(s.charAt(j));
            }
            s = t.toString();
        }
        return s;
    }

}
